<?php 
session_start();
if (isset($_POST['name']) && isset($_POST['fdes'])){
    $openid=trim(addslashes($_POST['fdes']));
	$name=trim(addslashes($_POST['name']));
	$phone=trim(addslashes($_POST['phone']));
	$nianji=trim(addslashes($_POST['nianji']));

	if (empty($name) || empty($phone) || empty($nianji)){
	    echo json_encode(array('s'=>'not','msg'=>'empty'));
	    exit;
	}
	include_once("../c/config.php");
	$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
	if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
	
	$mingTable='m3';
	if(3 == $nianji){
	    $mingTable='m3';
	}
	if(4 == $nianji){
	    $mingTable='m4';
	}
	if(5 == $nianji){
	    $mingTable='m5';
	}
	if(6 == $nianji){
	    $mingTable='m6';
	}

	$sql="select id,qu,school from ".$mingTable." where name='".$name."' and phone='".$phone."'  limit 0, 1";
	$query=$mysqli->query($sql);
    if($query->num_rows>0){
        $getU=$query->fetch_assoc();
        /**
        if(3 == $nianji){
            $table='check3';
        }else{
            $table='check3';
        } */
        $table='check3';
        $_SESSION['nianji']=$nianji;
        $sql="select id from ".$table." where openid='".$openid."'  limit 0, 1";
        $query=$mysqli->query($sql);
        if($query->num_rows>0){}else{
            $mysqli->query("insert into ".$table."(openid,nianji,mid,createtime) values('".$openid."','".$nianji."','".$getU['id']."','".date("Y-m-d H:i:s")."') ");
        }
        echo json_encode(array('s'=>'ok','q'=>$getU['qu'],'x'=>$getU['school']));
    }else{
        echo json_encode(array('s'=>'not'));
    }
    $mysqli->close();
}else{
    echo json_encode(array('s'=>'not'));
}
?>